package com.jzo2o.customer.controller.consumer;

import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import com.jzo2o.mvc.utils.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户地址簿相关接口
 */
@Slf4j
@RequestMapping("/consumer/address-book")
@RestController("consumerAddressController")
@Api(tags = "用户端 - 地址簿相关接口")
public class AddressBookController {
    @Resource
    IAddressBookService addressBookService;

    /**
     * 新增地址
     */
    @PostMapping
    @ApiOperation("新增地址")
    public void insert(@RequestBody AddressBookUpsertReqDTO dto) {
        addressBookService.addAddress(dto);

    }

    /**
     * 分页查询地址
     */
    @GetMapping("/page")
    @ApiOperation("查询地址")
    public PageResult<AddressBookResDTO> queryAddressPage(AddressBookPageQueryReqDTO dto) {
        return addressBookService.queryAddressPage(dto);
    }

    /**
     * 地址簿详情接口
     */
    @GetMapping("/{id}")
    @ApiOperation("地址簿详情接口")
    public AddressBook getDetail(@PathVariable Long id) {
        return addressBookService.getDetail(id);
    }

    /**
     * 地址簿修改接口
     */
    @PutMapping("/{id}")
    @ApiOperation("修改地址")
    public void update(@RequestBody AddressBookUpsertReqDTO dto,@PathVariable Long id) {
        addressBookService.updateAddress(dto,id);
    }

    /**
     * 批量删除地址
     */
    @DeleteMapping("/batch")
    @ApiOperation("批量删除地址")
    public void delete(@RequestBody List<Long> ids) {
        addressBookService.removeByIds(ids);
    }

    /**
     * 设置/取消默认地址
     */
    @PutMapping("/default")
    @ApiOperation("设置取消地址")
    public void setDefault(Integer flag,Long id) {
        addressBookService.defualt(flag,id);
    }
    /**
     * 获取默认地址信息
     */
    @GetMapping("/defaultAddress")
    @ApiOperation("获取默认地址接口")
    public AddressBook getDefaultAddress() {
        return addressBookService.getDefualt();
    }

}
